﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Distrackting.BusinessLayer;
using Distrackting.DataLayer;

namespace Distrackting.PresentationLayer
{
    public partial class VerPerc : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                if (Request.QueryString["perc"] == null)
                {
                    Mensagens.AdicionarErro("Percurso inválido.");
                    Response.Redirect(ResolveUrl("Public.aspx"));
                }
                else if (Convert.ToInt32(Session["user_level"]) >= 70)
                {
                    Button8.Visible = true;
                }
                initPerc();
            }
            catch (Exception ex)
            {
                Mensagens.AdicionarErro(ex.Message);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                String nomefich = Parser.Exportador.exportarFicheiroGPS(new Guid(Request.QueryString["perc"].ToString()), ResolveUrl("~/"));
                Response.TransmitFile(nomefich);

            }
            catch (Exception ex)
            {
                Mensagens.AdicionarErro(ex.ToString());
            }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            Guid cod_utilizador = new Guid(Session["user_guid"].ToString());
            Guid cod_perc = new Guid(Request.QueryString["perc"].ToString());
            GerirPercursos.marcarPercursoDebaixoOlho(cod_perc, cod_utilizador);

        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            Guid cod_utilizador = new Guid(Session["user_guid"].ToString());
            Guid cod_perc = new Guid(Request.QueryString["perc"].ToString());
            GerirPercursos.desmarcarPercursoDebaixoOlho(cod_perc, cod_utilizador);
        }

        protected void ButtonComentario_Click(object sender, EventArgs e)
        {
            Guid cod_utilizador = new Guid(Session["user_guid"].ToString());
            Guid cod_perc = new Guid(Request.QueryString["perc"].ToString());
            GerirPercursos.adicionaComentario(cod_utilizador, cod_perc, TextBoxComentario.Text.ToString());
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            try
            {
                Guid cod_utilizador = new Guid(Session["user_guid"].ToString());
                Guid cod_perc = new Guid(Request.QueryString["perc"].ToString());
                String testemunho = TextBox18.Text;
                GerirPercursos.createTestemunho(cod_utilizador, cod_perc, testemunho, Convert.ToInt32(DropDownRating.SelectedValue));
               
                initPerc();
            }
            catch (Exception ex)
            {
                Mensagens.AdicionarErro(ex.Message);
            }
        }


        public void initPerc()
        {
            Guid cod_perc = new Guid(Request.QueryString["perc"].ToString());
            Label1.Text = GerirPercursos.getPercurso(cod_perc).nome;

            HyperLink4.NavigateUrl = "VerPerc.aspx?perc={" + cod_perc + "}";
            HyperLink1.NavigateUrl = "VerPercMapa.aspx?perc={" + cod_perc + "}";
            HyperLink2.NavigateUrl = "VerPercFotos.aspx?perc={" + cod_perc + "}";
            HyperLink3.NavigateUrl = "VerPercTest.aspx?perc={" + cod_perc + "}";


        }

        protected void Button8_Click(object sender, EventArgs e)
        {

            Guid cod_perc = new Guid(Request.QueryString["perc"].ToString());
            GerirPercursos.apagaPercurso(cod_perc);
        }


    }
}

